<template>
    <div>
        <h3>房号列表</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>房号名称</td>
                    <td><input type="text" v-model="a.HouseName"></td>
                </tr>
                <tr>
                    <td>门店</td>
                    <td><select v-model="a.ShopId">
                            <option value="">请选择</option>
                            <option :value="item.Id" v-for="item in data.shopList" :key="item.Id">{{ item.ShopName }}
                            </option>
                        </select></td>
                </tr>
                <tr>
                    <td>房型</td>
                    <td><select v-model="a.HouseTypeId">
                            <option value="">请选择</option>
                            <option :value="item.Id" v-for="item in data.housetypeList" :key="item.Id">
                                {{ item.HouseTypeName }}</option>
                        </select></td>
                </tr>
                <tr>
                    <td>房态</td>
                    <td><select v-model="a.HouseStates">
                            <option value="">请选择</option>
                            <option :value="1">空闲</option>
                            <option :value="2">已入住</option>
                            <option :value="3">预约</option>
                        </select></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="添加" @click="ok"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import axios from 'axios';
import moment from 'moment';
const router = useRouter();
const route = useRoute();

onMounted(() => {
    getshoplist();
    gettypelist();
})

let a: any = reactive({
    HouseName: '',
    ShopId: '',
    HouseTypeId: '',
    HouseStates: ''
})
//接收门店列表
let data: any = reactive({
    shopList: [],
    housetypeList: [],
})

//接收门店数据
const getshoplist = () => {
    axios({
        method: 'get',
        url: '/api/Shop/GetShopList',
        params: {
            pageSize: 99,
            pageIndex: 1
        }
    })
        .then((res) => {
            console.log(res)
            data.shopList = res.data.list;


        })
        .catch((err) => {
            console.log(err);
        })
}

const gettypelist = () => {
    axios({
        url: 'api/HouseType/ShowHouse',
        method: 'get',
        params: {
            pageYe: 1,
            pageHang: 99
        }
    })
        .then((res) => {
            console.log(res);
            data.housetypeList = res.data.list;
        })
}

const ok: any = () => {
    axios({
        url: '/api/HouseNumber/HouseNoAdd',
        method: 'post',
        data: a
    })
        .then((res) => {
            if (res.data == -1) {
                alert("重复");
                return;
            }
            if (res.data > 0) {
                alert("成功");
                router.push("/housenumbershow")
            }
        })
}

</script>

<style scoped></style>